home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / bother__ / cenvid.zip / CENVIDOS.ZIP / WINCLIP.LIB < prev    next >
Text File  |  1995-03-28  |  9KB  |  273 lines

  1. // WinClip.lib - Functions for reading from and writing
  2. // ver.1         to the Windows clipboard from DOS.
  3. //
  4. //**** GetClipboardText() Read text string from Windows clipboard
  5. // SYNTAX: string GetClipboardText()
  6. // RETURN: NULL if cannot find or retrieve clipboard text, else return
  7. //         null-terminated string of clipboard data
  8. //
  9. //
  10. //**** PutClipboardText() Write text string to the Windows clipboard
  11. // SYNTAX: bool PutClipboardText(string Text)
  12. // WHERE: Text: null-terminated string to write to clipboard; or NULL
  13. //        to delete the contents of the clipboard
  14. //
  15.  
  16. if !defined(_DOS_)
  17.    printf("\n\a\aWinClip must execute from CEnviD for DOS.\n"),
  18.    exit(EXIT_FAILURE);
  19.  
  20. ClipboardAvailable() // return True if functions available, else False
  21. {
  22.    RegIn.ax = 0x1700;
  23.    interrupt(0x2f,RegIn,RegOut);
  24.    if ( RegOut.ax == 0x1700 ) {
  25.       printf("\nClipboard functions not available\n");
  26.       return False;
  27.    }
  28.    return True;
  29. }
  30.  
  31. OpenClipboard() // return True for success, else False
  32. {
  33.    RegIn.ax = 0x1701;
  34.    interrupt(0x2F,RegIn,RegOut);
  35.    if ( RegOut.ax == 0 ) {
  36.       printf("\nUnable to open clipboard.\n");
  37.       return False;
  38.    }
  39.    return True;
  40. }
  41.  
  42. CloseClipboard() // return True for success, else False
  43. {
  44.    RegIn.ax = 0x1708;
  45.    interrupt(0x2F,RegIn,RegOut);
  46.    if ( RegOut.ax == 0 ) {
  47.       printf("\nUnable to open clipboard.\n");
  48.       return False;
  49.    }
  50.    return True;
  51. }
  52.  
  53. GetClipboardDataSize(pType) // return size of data in clipboard; 0 if none
  54. {
  55.    RegIn.ax = 0x1704;
  56.    RegIn.dx = pType;
  57.    interrupt(0x2F,RegIn,RegOut);
  58.    return ( RegOut.ax | (RegOut.dx << 16) );
  59. }
  60.  
  61. GetClipboardData(pBuf,pType)  // assume that pBuf is big enough
  62. {
  63.    RegIn.ax = 0x1705;
  64.    RegIn.dx = pType;
  65.    RegIn.es = segment(pBuf);  RegIn.bx = offset(pBuf);
  66.    interrupt(0x2F,RegIn,RegOut);
  67.    if ( 0 == RegOut.ax ) {
  68.       printf("\nError on GetClipboardData\n");
  69.       return False;
  70.    }
  71.    return True;
  72. }
  73.  
  74. GetClipboardText()
  75. {
  76.    lText = NULL; // assume failure
  77.    if ( ClipboardAvailable() && OpenClipboard() ) {
  78.       if ( lClipboardSize = GetClipboardDataSize(1) ) {
  79.          undefine(lText);
  80.          lText[lClipboardSize] = '\0';
  81.          if ( !GetClipboardData(lText,1) )
  82.             lText = NULL;
  83.          else
  84.             SetArraySpan(lText,strlen(lText));
  85.       }
  86.       CloseClipboard();
  87.    }
  88.    return lText;
  89. }
  90.  
  91. EmptyClipboard()
  92. {
  93.    RegIn.ax = 0x1702;
  94.    interrupt(0x2F,RegIn,RegOut);
  95.    if ( RegOut.ax == 0 ) {
  96.       printf("\Error on EmptyClipboard()\n");
  97.       return False;
  98.    }
  99.    return True;
  100. }
  101.  
  102. ClipboardCompact(pSize)
  103. {
  104.    RegIn.ax = 0x1702;
  105.    RegIn.si = (pSize >> 16 & 0xFFFF); RegIn.cx = pSize & 0xFFFF;
  106.    interrupt(0x2F,RegIn,RegOut);
  107.    return ( RegOut.ax | (RegOut.dx << 16) );
  108. }
  109.  
  110. SetClipboardData(pBuf,pBufSize,pType)
  111. {
  112.    RegIn.ax = 0x1703;
  113.    RegIn.dx = pType;
  114.    RegIn.es = segment(pBuf);  RegIn.bx = offset(pBuf);
  115.    RegIn.si = (pBufSize >> 16 & 0xFFFF); RegIn.cx = pBufSize & 0xFFFF;
  116.    interrupt(0x2F,RegIn,RegOut);
  117.    if ( RegOut.ax == 0 ) {
  118.       printf("\Error on SetClipboardData()\n");
  119.       return False;
  120.    }
  121.    return True;
  122. }
  123.  
  124. PutClipboardText(pText)
  125. {
  126.    lSuccess = False; // assume failure
  127.    if ( ClipboardAvailable() && OpenClipboard() ) {
  128.       if ( EmptyClipboard() ) {
  129.          if ( !pText ) {
  130.             lSuccess = True;
  131.          } else {
  132.             lTextLen = strlen(pText);
  133.             if ( ClipboardCompact(lTextLen+1)
  134.               && SetClipboardData(pText,lTextLen+1,1) ) {
  135.                lSuccess = True;
  136. }
  137.          }
  138.       }
  139.       CloseClipboard();
  140.    }
  141.    return lSuccess;
  142. }
  143.  
  144. //Parameters      AX = 1704H
  145. //                DX = WinOldAp-Supported Clipboard format
  146. //Return Values   DX:AX == Size of the data in bytes, including any
  147. //                         headers.
  148. //                      == 0 If data in this format is not in the clipboard.
  149. //
  150. //Name            IdentifyWinOldApVersion()
  151. //Parameters      AX = 1700H
  152. //Return Values   AX == 1700H: Clipboard functions not available
  153. //                   <> 1700H: AL = Major version number
  154. //                             AH = Minor version number
  155. //
  156. //Name            OpenClipboard()
  157. //Parameters      AX = 1701H
  158. //Return Values   AX == 0: Clipboard already open
  159. //                   <> 0: Clipboard opened
  160. //
  161. //Name            EmptyClipboard()
  162. //Parameters      AX = 1702H
  163. //Return Values   AX == 0: Error occurred
  164. //                   <> 0: OK, Clipboard emptied
  165. //
  166. //Name            SetClipboardData()
  167. //Parameters      AX = 1703H
  168. //                DX = WinOldAp-Supported Clipboard format
  169. //                ES:BX = Pointer to data
  170. //                SI:CX = Size of data in bytes
  171. //Return Values   AX == 0: Error occurred
  172. //                   <> 0: OK.  Data copied into allocated memory.
  173. //Note            The MS-DOS application should call the
  174. //                ClipboardCompact() function prior to this to determine
  175. //                if the data can be accommodated in memory.
  176. //
  177. //Name            GetClipboardDataSize()
  178. //Parameters      AX = 1704H
  179. //                DX = WinOldAp-Supported Clipboard format
  180. //Return Values   DX:AX == Size of the data in bytes, including any
  181. //                         headers.
  182. //                      == 0 If data in this format is not in the clipboard.
  183. //
  184. //Name            GetClipboardData()
  185. //Parameters      AX = 1705H
  186. //                DX = WinOldAp-Supported Clipboard format
  187. //                ES:BX = Pointer to data buffer to hold data
  188. //Return Values   AX == 0: Error occurred (or data in this format is not
  189. //                         in the clipboard)
  190. //                   <> 0: OK
  191. //Note           This call should be preceded by a
  192. //               GetClipBoardDataSize() call to find out how much memory
  193. //               is required for the buffer. No checking is performed, the
  194. //
  195. //               caller must ensure that the buffer is big enough;
  196. //               otherwise, some of the callers code or data may be
  197. //               overwritten.
  198. //
  199. //Name            CloseClipboard()
  200. //Parameters      AX = 1708H
  201. //Return Values   AX == 0: Error occurred
  202. //                   <> 0: OK
  203. //
  204. //
  205. //Name            ClipboardCompact()
  206. //Parameters      AX = 1709H
  207. //                SI:CX = Desired memory size in bytes.
  208. //Return Values   DX:AX == Number of bytes of largest block of free memory.
  209. //                      == 0 if error or no memory
  210. //Notes           The MS-DOS application is responsible for including the
  211. //                size of any headers in the desired memory size.
  212. //
  213. //
  214. //
  215. //Name            GetDeviceCaps()
  216. //Parameters      AX = 170AH
  217. //                DX = GDI information index
  218. //Return Values   AX == integer value of desired item
  219. //                   == 0 if error
  220. //Notes           The implied hDC for this call will be for the display.
  221. //
  222. //
  223. //
  224. //Supported Clipboard Formats
  225. //---------------------------
  226. //
  227. //
  228. //
  229. //The following Windows clipboard formats are supported:
  230. //
  231. //
  232. //
  233. //   CF_TEXT         = 1
  234. //   CF_BITMAP       = 2         ; See structures section
  235. //   CF_OEMTEXT      = 7
  236. //   CF_DSPTEXT      = 81h
  237. //   CF_DSPBITMAP    = 82h
  238. //Note: Since the RegisterClipboardFormat() and EnumClipboardFormats()
  239. //      functions are not available at this time, the use of private
  240. //      clipboard formats is not supported.
  241. //Structures
  242. //----------
  243. //
  244. //
  245. //
  246. //These structures mimic the actual Windows structures with one major
  247. //difference: instead of including a handle or pointer to other memory
  248. //containing the actual data, the data follows the structure. The
  249. //structure information now behaves like a header prefacing the data.
  250. //
  251. //
  252. //
  253. //Bitmap structure:
  254. //
  255. //
  256. //
  257. //   bmType          DW      ?   ; Always 0
  258. //   bmWidth         DW      ?   ; Width of bitmap in pixels
  259. //   bmHeight        DW      ?   ; Height of bitmap in raster lines
  260. //   bmWidthBytes    DW      ?   ; Bytes/raster line
  261. //   bmPlanes        DB      ?   ; Number of color planes in the bitmap
  262. //   bmBitsPixel     DB      ?   ; Number of adj color bits to def pixel
  263. //   bmBits          DQ      ?   ; Points to byte following bmHigDim
  264. //   bmWidDim        DW      ?   ; Width of bitmap in 0.1 mm units
  265. //
  266. //   bmHigDim        DW      ?   ; Height of bitmap in 0.1 mm units
  267. //   BitmapData      nBytes      ; The actual data
  268. //
  269. //
  270. //
  271. //#:x218a
  272. //
  273.